package com.smart_campus.teg.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.smart_campus.sys.common.DataGridView;
import com.smart_campus.teg.vo.ClassVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import com.smart_campus.teg.domain.TegClass;
import com.smart_campus.teg.mapper.TegClassMapper;
import com.smart_campus.teg.service.TegClassService;

import java.util.List;

@Service
public class TegClassServiceImpl implements TegClassService{

    @Autowired
    private TegClassMapper tegClassMapper;

    //@CacheEvict 删除的注解通过对象id在redis中删除数据
    @CacheEvict(cacheNames = "com.smart_campus.teg.service.impl.TegClassServiceImpl",key = "#classId")
    @Override
    public int deleteByPrimaryKey(Integer classId) {
        return tegClassMapper.deleteByPrimaryKey(classId);
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.teg.service.impl.TegClassServiceImpl",key = "#result.classId")
    @Override
    public TegClass insert(TegClass record) {
        tegClassMapper.insert(record);
        return record;
    }

    //@Cacheable 返回对象 通过对象id在redis中创建对象保存,方便下次使用
    @Cacheable(cacheNames ="com.smart_campus.teg.service.impl.TegClassServiceImpl",key = "#classId")
    @Override
    public TegClass selectByPrimaryKey(Integer classId) {
        return tegClassMapper.selectByPrimaryKey(classId);
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.teg.service.impl.TegClassServiceImpl",key = "#result.classId")
    @Override
    public TegClass updateByPrimaryKeySelective(TegClass record) {
        tegClassMapper.updateByPrimaryKeySelective(record);
        return record;
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.teg.service.impl.TegClassServiceImpl",key = "#result.classId")
    @Override
    public TegClass updateByPrimaryKey(TegClass record) {
        tegClassMapper.updateByPrimaryKey(record);
        return record;
    }

    @Override
    public DataGridView selClass(ClassVo vo) {
        Page<Object> page = PageHelper.startPage(vo.getPage(),vo.getLimit());
        List<ClassVo> list = tegClassMapper.selClass(vo);
        return new DataGridView(page.getTotal(),list);
    }

    @Override
    public DataGridView selClassname() {
        List<ClassVo> list = tegClassMapper.selClassname();
        return new DataGridView(list);
    }

}
